package com.example.springbootdemo.impot;

import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

public class MyCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        // 可以获取bean工厂
        final ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();

        // bean定义注册，可以管理所有bean
        final BeanDefinitionRegistry registry = context.getRegistry();

        // 可以获取所有环境变量
        final Environment environment = context.getEnvironment();
        final String property = environment.getProperty("os.name");
        System.out.println("os.name:" + property);
        assert property != null;
        if (property.contains("Windows")){
            return true;
        }
        return false;
    }
}
